package com.ppl.server.boot;

import akka.actor.ActorSystem;
import akka.kernel.Bootable;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.ppl.server.modules.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * User: Vincent
 * Date: 11/16/12
 * Time: 4:52 PM
 */
public class Boot implements Bootable {

    Logger log = LoggerFactory.getLogger(Boot.class);

    public static ActorSystem actorSystem;

    @Inject
    private static HttpConnector httpConnector;

    @Inject
    public static Injector injector;
    private Config.HttpServerStartUp httpServerStartUpServer;

//    public static ActorRef cacheEvictionActor;

    /**
     * Callback run on microkernel startup.
     * Create initial actors and messages here.
     */
    @Override
    public void startup() {
        actorSystem = ActorSystem.create("BackEndSystem");

        injector =  Guice.createInjector(
                new Config());

        try {
            httpConnector.startup();
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }


    }

    /**
     * Callback run on microkernel shutdown.
     * Shutdown actor systems here.
     */
    @Override
    public void shutdown() {
        httpServerStartUpServer.shutdown();
        actorSystem.shutdown();
    }
}
